package com.tamecode.chapter06.sec45;

import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSource;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.GregorianCalendar;
import java.util.Locale;

/**
 * @Author: Qiongchao
 * @Version: 1.0.0
 * @Date: 2023/9/27
 */
public class ResBundleMsgStarter {
    public static void main(String[] args) {
        String[] configs = {"sec6-45/i18n/beans-resBundle.xml"};
        ApplicationContext ctx = new ClassPathXmlApplicationContext(configs);
        //①获取 MessageSource 的 Bean
        MessageSource ms = (MessageSource)ctx.getBean("myResource");
        Object[] params = {"John", new GregorianCalendar(). getTime()};
        //②获取格式化的国际化信息
        String str1 = ms.getMessage("greeting.common",params, Locale.US);
        String str2 = ms.getMessage("greeting.morning",params,Locale.CHINA);
        String str3 = ms.getMessage("greeting.afternoon",params,Locale.CHINA);
        System.out.println(str1); // How are you!John,today is 9/27/23 10:51 PM
        System.out.println(str2); // 早上好!John, 现在是 下午10:51
        System.out.println(str3); // 下午好!John, 现在是 2023年9月27日
    }
}
